<?php
session_start();
require "config.php";
require "language.php";
require "functions.php";
if(isset($_POST['submit']))
{
	change_db($realm_DB);
	$user_name = $_POST['username'];
	$user_pass = sha1(strtoupper($_POST['username'].":".$_POST['password']));
	$select_acc = "SELECT id, username FROM account WHERE username='$user_name' AND sha_pass_hash='$user_pass'";
	$results=mysql_query($select_acc) or die (mysql_error());
	if(mysql_num_rows($results) == 1)
	{
		$row=mysql_fetch_array($results);
		$_SESSION['user_id'] = $row['id'];
		$_SESSION['user_name'] = $row['username'];
		$_SESSION['logged_voting'] = 1;
		header ("Refresh: 0; URL=index.php");
	}
	else
	{
?>
<script type="text/javascript">
function back()
{
  document.location.href="<?php echo 'Azeroth-Gaming'; ?>";
}
</script>
<table width='100%' border='0'>
	<tr>
		<td align='left'><?php require "language_form.php"; ?></td>
		<td align='right'><input type='button' onclick="back()" value='<?php echo $language['back_to_site'] ?>'/></td>
	</tr>
</table>
<?php
		require "title.php";
?>
<p align='center'><font color="red"><?php echo $language['wrong'] ?></font></p>
<form action="login.php" method="post">
<table border='1' cellspacing='1' cellpadding='3' align='center'>
	<tr>
		<td width='50%'><?php echo $language['username'] ?></td>
		<td width='50%'><input type="text" name="username"/></td>
	</tr>
	<tr>
		<td><?php echo $language['password'] ?></td>
		<td><input type="password" name="password"/></td>
	</tr>
	<tr>
		<td colspan='2' align='center'>
			<input type="submit" name="submit" value="<?php echo $language['submit'] ?>"/>
			<input type='reset' value='<?php echo $language['reset'] ?>'/>
		</td>
	</tr>
</table>
</form>
<?php
	}
}
else
{
?>
<script type="text/javascript">
function back()
{
  document.location.href="<?php echo $site_link; ?>";
}
</script>
<table width='100%' border='0'>
	<tr>
		<td align='left'><?php require "language_form.php"; ?></td>
		<td align='right'>
			<input type='button' onclick="back()" value='<?php echo $language['back_to_site'] ?>'/>
		</td>
	</tr>
</table>
<?php
	require "title.php";
?>
<p align='center'><?php echo $language['enter_name_and_pass'] ?></p>
<form action="login.php" method="post">
<table border='1' cellspacing='1' cellpadding='3' align='center'>
	<tr>
		<td width='50%'><?php echo $language['username'] ?></td>
		<td width='50%'><input type="text" name="username"/></td>
	</tr>
	<tr>
		<td><?php echo $language['password'] ?></td>
		<td><input type="password" name="password"/></td>
	</tr>
	<tr>
		<td colspan='2' align='center'>
			<input type="submit" name="submit" value="<?php echo $language['submit'] ?>"/>
			<input type='reset' value='<?php echo $language['reset'] ?>'/>
		</td>
	</tr>
</table>
</form>
<?php
}
?>